package org.aplikator.client.shared.descriptor;

import com.google.gwt.user.client.ui.Widget;
import org.aplikator.client.local.widgets.HasFields;
import org.aplikator.client.local.widgets.PaneWidget;
import org.jboss.errai.common.client.api.annotations.Portable;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("serial")
//@JsonTypeName("panel")
//@Portable
public class PanelDTO extends WidgetDTO implements RenderWidgetAware {

	public static final String TYPE_KEY ="panel";
	
    private List children = new ArrayList();
    private boolean frame = false;
    private boolean horizontal = false;

    @SuppressWarnings("unused")
    public PanelDTO(){} //TODO custom marshaller

    public PanelDTO(boolean horizontal) {
        this.horizontal = horizontal;
    }

    @Override
    public Widget getWidget(HasFields form) {
        PaneWidget pane = new PaneWidget(null, frame, horizontal, getSize());
        for (Object chobj : children) {
        	WidgetDTO childDescriptor = (WidgetDTO) chobj;
        	pane.add(((RenderWidgetAware)childDescriptor).getWidget(form));
        }
        return pane;
    }

    @SuppressWarnings("unchecked")
    public PanelDTO addChild(WidgetDTO child) {
        children.add(child);
        return this;
    }

    public List getChildren() {
    	return this.children;
    }

    public void setChildren(List children) {
		this.children = children;
	}
    
    public void setFrame(boolean frame) {
        this.frame = frame;
    }

    public boolean isFrame() {
        return frame;
    }

    public boolean isHorizontal() {
		return horizontal;
	}
    
    public void setHorizontal(boolean horizontal) {
		this.horizontal = horizontal;
	}
}
